package com.partners.controller;

import com.partners.annotation.SimpleParam;
import com.partners.dao.dto.PayOrderOutputDTO;
import com.partners.model.ApiResult;
import com.partners.service.PayService;
import com.partners.utils.ApiResultUtil;
import com.partners.utils.RequestUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 发红包
 * @author liangyongle
 * @date 2019-01-12
 */
@RestController
@RequestMapping("redPacket")
public class RedPacketController {


   @Resource
   private PayService payService;


   @PostMapping("/send")
   public ApiResult sendRedPacket(HttpServletRequest request){
       String ip = RequestUtils.getIpAddress(request);
      payService.sendRedPacket(ip);
       return ApiResultUtil.ok(0);
   }



    @PostMapping("/pay_order")
    public ApiResult<PayOrderOutputDTO> payOrder(@SimpleParam("order_id") Integer orderId,HttpServletRequest request){
        String ip = RequestUtils.getIpAddress(request);

        PayOrderOutputDTO result  = payService.createPayInfo(orderId,ip);

        return ApiResultUtil.ok(result);
    }


}
